import 'package:flutter/material.dart';

class BlockProgress extends StatelessWidget {
  final int totalBlocks;
  final int lines;
  final int columns;
  final double progress;
  final double width;
  final double height;
  final double _gap = 2;

  const BlockProgress(
      {super.key,
      required this.totalBlocks,
      required this.lines,
      required this.columns,
      required this.progress,
      required this.width,
      required this.height});

  @override
  Widget build(BuildContext context) {
    final filledBlocks = (progress * totalBlocks).floor();

    return GridView.count(
      crossAxisCount: columns,
      mainAxisSpacing: 2,
      crossAxisSpacing: 2,
      childAspectRatio: (width - _gap * (columns - 1)) /
          columns /
          (height - _gap * (lines - 1)) *
          lines,
      children: List.generate(
          totalBlocks, (index) => _getBlock(index, filledBlocks, context)),
    );
  }

  Widget _getBlock(int index, int filledBlocks, BuildContext context) {
    return Container(
      color: index < filledBlocks
          ? Theme.of(context).colorScheme.primary
          : Theme.of(context).colorScheme.surface,
    );
  }
}
